<div class="selenium-notes">
<h1>Auto-Suggest Dropdown in Selenium WebDriver</h1>
<p>An <strong>Auto-Suggest Dropdown</strong>, also called an <strong>Autocomplete Dropdown</strong>, is a dynamic web component that displays a list of suggestions while the user types text into an input field. The suggestions may be generated from local data, JavaScript logic, an API, AJAX requests, or a server-side search.</p>
<p>Auto-suggest dropdowns are commonly used in search boxes, country selection, city selection, flight booking applications, hotel booking applications, e-commerce websites, address fields, employee search fields, customer selection fields, and many other modern web applications.</p>
<p>In Selenium WebDriver automation, an auto-suggest dropdown is usually handled differently from a normal HTML dropdown because its suggestions are often created dynamically after the user enters text.</p>
<p><strong>Important:</strong> Selenium's <code>Select</code> class is intended for actual HTML <code><select></code> elements and their <code><option></code> elements. Custom dropdowns built using elements such as <code>div</code>, <code>ul</code>, and <code>li</code> need normal WebElement interactions instead. <a href="https://www.selenium.dev/documentation/webdriver/support_features/select_lists/" target="_blank" rel="noopener noreferrer">Selenium Select Documentation</a></p>
<p><a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Selenium Training Course</a> | <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Course Demo</a></p>
<hr>
<h2>1. What is an Auto-Suggest Dropdown?</h2>
<p>An Auto-Suggest Dropdown is a user-interface component that automatically displays possible matching values as the user types into an input field.</p>
<p>For example, when the user enters <strong>Ind</strong> in a country search field, the application may display:</p>
<ul>
<li>India</li>
<li>Indonesia</li>
<li>Indiana</li>
<li>Indore</li>
</ul>
<p>The user can then select the required suggestion from the dynamically displayed list.</p>
<h2>2. Simple Auto-Suggest Example</h2>
<pre><code><input type="text" id="country" placeholder="Search country">
<ul class="suggestions">
<li>India</li>
<li>Indonesia</li>
<li>Iceland</li>
</ul></code></pre>
<h2>3. How Auto-Suggest Works</h2>
<pre><code>User enters text
↓
Input event is triggered
↓
Application processes the text
↓
API / AJAX / local filtering
↓
Matching results are generated
↓
DOM is updated
↓
Suggestions become visible
↓
User selects a suggestion</code></pre>
<h2>4. Why Auto-Suggest Dropdowns Are Important in Selenium</h2>
<p>Auto-suggest dropdowns are important in Selenium because modern web applications frequently use dynamic UI components instead of traditional HTML controls. The suggestion elements may not exist when the page initially loads and may be inserted or replaced after typing.</p>
<p>Therefore, automation needs proper element identification, synchronization, dynamic element handling, and verification.</p>
<h2>5. Auto-Suggest Dropdown vs Normal Dropdown</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Feature</th><th>Normal HTML Dropdown</th><th>Auto-Suggest Dropdown</th></tr>
<tr><td>Typical HTML</td><td><code><select></code></td><td><code>input</code>, <code>div</code>, <code>ul</code>, <code>li</code></td></tr>
<tr><td>Options</td><td>Usually represented by <code><option></code></td><td>Often dynamically generated</td></tr>
<tr><td>Selection</td><td>Select an option</td><td>Type and select suggestion</td></tr>
<tr><td>Select class</td><td>Supported</td><td>Generally not applicable</td></tr>
<tr><td>AJAX/API</td><td>Usually unnecessary</td><td>Frequently used</td></tr>
<tr><td>Waiting</td><td>Often simpler</td><td>Usually requires synchronization</td></tr>
<tr><td>Dynamic DOM</td><td>Less common</td><td>Very common</td></tr>
</table>
<h2>6. Important Rule About Selenium Select</h2>
<p>The Selenium <code>Select</code> class should be used only when the target element is an HTML <code><select></code>. Selenium documentation explicitly states that the Select class works with <code>select</code> and <code>option</code> elements and does not work with JavaScript dropdowns created using elements such as <code>div</code> or <code>li</code>.</p>
<pre><code>WebElement element =
driver.findElement(By.id("country"));
Select select = new Select(element);</code></pre>
<p>The above code is appropriate only when <code>country</code> identifies a real <code><select></code> element.</p>
<h2>7. Basic Auto-Suggest HTML Structure</h2>
<pre><code><div class="search-container">
<input
id="country"
type="text"
placeholder="Search country">
<ul class="suggestions">
<li>India</li>
<li>Indonesia</li>
<li>Iceland</li>
</ul>
</div></code></pre>
<h2>8. Basic Selenium Automation Flow</h2>
<pre><code>Open application
↓
Locate input field
↓
Click input if required
↓
Enter search text
↓
Wait for suggestions
↓
Locate required suggestion
↓
Click suggestion
↓
Verify selected value</code></pre>
<h2>9. Basic Java Selenium Example</h2>
<pre><code>import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AutoSuggestExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
WebElement input =
driver.findElement(By.id("country"));
input.sendKeys("Ind");
WebElement option =
driver.findElement(
By.xpath("//li[normalize-space()='India']")
);
option.click();
} finally {
driver.quit();
}
}
}</code></pre>
<h2>10. Locating the Input Field</h2>
<p>The first step in automating an auto-suggest dropdown is to locate the input element where the user enters the search text.</p>
<pre><code>WebElement input =
driver.findElement(By.id("country")); </code></pre>
<h2>11. Using ID Locator</h2>
<pre><code>WebElement input =
driver.findElement(By.id("country"));
input.sendKeys("Ind");</code></pre>
<h2>12. Using Name Locator</h2>
<pre><code>WebElement input =
driver.findElement(By.name("country"));
input.sendKeys("Ind");</code></pre>
<h2>13. Using CSS Selector</h2>
<pre><code>WebElement input =
driver.findElement(
By.cssSelector("input#country")
);
input.sendKeys("Ind");</code></pre>
<h2>14. Using XPath</h2>
<pre><code>WebElement input =
driver.findElement(
By.xpath("//input[@id='country']")
);
input.sendKeys("Ind");</code></pre>
<h2>15. Using Placeholder Attribute</h2>
<pre><code>WebElement input =
driver.findElement(
By.xpath("//input[@placeholder='Search country']")
);
input.sendKeys("Ind");</code></pre>
<h2>16. Entering Search Text</h2>
<p>Once the input is located, use <code>sendKeys()</code> to enter the text that should generate suggestions.</p>
<pre><code>input.sendKeys("Ind");</code></pre>
<h2>17. Clearing Existing Text</h2>
<pre><code>input.clear();
input.sendKeys("India");</code></pre>
<h2>18. Replacing Existing Text</h2>
<pre><code>input.click();
input.sendKeys(Keys.CONTROL, "a");
input.sendKeys("Mumbai");</code></pre>
<h2>19. Importing Keys</h2>
<pre><code>import org.openqa.selenium.Keys;</code></pre>
<h2>20. Why Suggestions Are Dynamic</h2>
<p>Auto-suggest results may be generated only after the application receives the text entered by the user. JavaScript may then filter local data or send a request to a backend service.</p>
<pre><code>Enter "Ind"
↓
JavaScript event
↓
Search/filter operation
↓
Results generated
↓
DOM updated
↓
Suggestions displayed</code></pre>
<h2>21. Dynamic DOM</h2>
<p>A major challenge with auto-suggest controls is that suggestion elements can be dynamically inserted, removed, or replaced.</p>
<p>For example, the following elements might not exist when the page first loads:</p>
<pre><code><li>India</li>
<li>Indonesia</li>
<li>Indore</li></code></pre>
<h2>22. Why Explicit Wait Is Important</h2>
<p>Because suggestions may appear after JavaScript or an API operation completes, Selenium should wait for the required condition instead of assuming that the suggestion is immediately available.</p>
<p>Selenium's waiting documentation explains that dynamic web applications can change the DOM after the browser has returned control to the test code. Explicit waits allow a test to wait for a specific condition. <a href="https://www.selenium.dev/documentation/webdriver/support_features/expected_conditions/" target="_blank" rel="noopener noreferrer">Selenium Expected Conditions</a></p>
<h2>23. Creating WebDriverWait</h2>
<pre><code>import java.time.Duration;
import org.openqa.selenium.support.ui.WebDriverWait;
WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);</code></pre>
<h2>24. Waiting for Suggestion Visibility</h2>
<pre><code>WebElement option = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath("//li[normalize-space()='India']")
)
);</code></pre>
<h2>25. Importing ExpectedConditions</h2>
<pre><code>import org.openqa.selenium.support.ui.ExpectedConditions;</code></pre>
<h2>26. Waiting for Clickability</h2>
<pre><code>WebElement option = wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath("//li[normalize-space()='India']")
)
);
option.click();</code></pre>
<h2>27. Complete Example with Explicit Wait</h2>
<pre><code>import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class AutoSuggestWaitExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
WebElement input =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.id("country")
)
);
input.sendKeys("Ind");
WebElement option =
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
);
option.click();
} finally {
driver.quit();
}
}
}</code></pre>
<h2>28. Selecting by Exact Visible Text</h2>
<pre><code>driver.findElement(
By.xpath("//li[normalize-space()='India']")
).click();</code></pre>
<h2>29. Why normalize-space() Is Useful</h2>
<p><code>normalize-space()</code> helps when the displayed text contains leading, trailing, or inconsistent whitespace.</p>
<pre><code>By.xpath("//li[normalize-space()='India']")</code></pre>
<h2>30. Using contains() in XPath</h2>
<p>When exact text is not stable, <code>contains()</code> can be used carefully.</p>
<pre><code>By.xpath(
"//li[contains(normalize-space(),'India')]"
)</code></pre>
<h2>31. Exact Text vs Partial Text</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Method</th><th>Example</th><th>Use</th></tr>
<tr><td>Exact</td><td><code>normalize-space()='India'</code></td><td>When text is stable</td></tr>
<tr><td>Partial</td><td><code>contains(normalize-space(),'India')</code></td><td>When text may contain additional information</td></tr>
</table>
<h2>32. Selecting the First Suggestion</h2>
<pre><code>WebElement firstOption =
driver.findElement(
By.cssSelector(".suggestions li")
);
firstOption.click();</code></pre>
<p>Selecting the first suggestion should be used only when the application's intended behavior requires the first result.</p>
<h2>33. Finding All Suggestions</h2>
<pre><code>List<WebElement> suggestions =
driver.findElements(
By.cssSelector(".suggestions li")
);</code></pre>
<h2>34. Importing List</h2>
<pre><code>import java.util.List;</code></pre>
<h2>35. Printing All Suggestions</h2>
<pre><code>List<WebElement> suggestions =
driver.findElements(
By.cssSelector(".suggestions li")
);
for (WebElement suggestion : suggestions) {
System.out.println(
suggestion.getText()
);
}</code></pre>
<h2>36. Selecting a Specific Suggestion</h2>
<pre><code>String expected = "India";
List<WebElement> suggestions =
driver.findElements(
By.cssSelector(".suggestions li")
);
for (WebElement suggestion : suggestions) {
if (suggestion.getText()
.trim()
.equals(expected)) {
suggestion.click();
break;
}
}</code></pre>
<h2>37. Case-Insensitive Selection</h2>
<pre><code>String expected = "india";
for (WebElement suggestion : suggestions) {
String actual =
suggestion.getText().trim();
if (actual.equalsIgnoreCase(expected)) {
suggestion.click();
break;
}
}</code></pre>
<h2>38. Handling Extra Spaces</h2>
<pre><code>String actual =
suggestion.getText().trim();
if (actual.equalsIgnoreCase("India")) {
suggestion.click();
}</code></pre>
<h2>39. Locating Suggestions with CSS</h2>
<pre><code>List<WebElement> suggestions =
driver.findElements(
By.cssSelector(".suggestions li")
);</code></pre>
<h2>40. Locating Suggestions with XPath</h2>
<pre><code>List<WebElement> suggestions =
driver.findElements(
By.xpath(
"//ul[contains(@class,'suggestions')]/li"
)
);</code></pre>
<h2>41. Using Data Attributes</h2>
<p>Custom data attributes can provide stable locators when available.</p>
<pre><code>WebElement option =
driver.findElement(
By.cssSelector("[data-value='India']")
);
option.click();</code></pre>
<h2>42. Dynamic IDs</h2>
<p>Some applications generate dynamic IDs such as:</p>
<pre><code>suggestion-101
suggestion-204
suggestion-309</code></pre>
<p>Depending directly on the changing number can make tests fragile.</p>
<h2>43. CSS Starts-With Selector</h2>
<pre><code>By.cssSelector("[id^='suggestion-']")</code></pre>
<h2>44. XPath starts-with()</h2>
<pre><code>By.xpath(
"//*[starts-with(@id,'suggestion-')]"
)</code></pre>
<h2>45. XPath contains() for Dynamic IDs</h2>
<pre><code>By.xpath(
"//*[contains(@id,'suggestion-')]"
)</code></pre>
<h2>46. Searchable Product Auto-Suggest</h2>
<pre><code>WebElement search =
driver.findElement(
By.id("productSearch")
);
search.sendKeys("Laptop");
WebElement product =
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='Laptop Pro']"
)
)
);
product.click();</code></pre>
<h2>47. City Auto-Suggest</h2>
<pre><code>WebElement city =
driver.findElement(By.id("city"));
city.sendKeys("Mum");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[normalize-space()='Mumbai']"
)
)
).click();</code></pre>
<h2>48. Country Auto-Suggest</h2>
<pre><code>WebElement country =
driver.findElement(By.id("country"));
country.sendKeys("Ind");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
).click();</code></pre>
<h2>49. Airport Auto-Suggest</h2>
<pre><code>WebElement departure =
driver.findElement(By.id("departure"));
departure.sendKeys("Del");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[contains(normalize-space(),'Delhi')]"
)
)
).click();</code></pre>
<h2>50. Address Auto-Complete</h2>
<pre><code>WebElement address =
driver.findElement(By.id("address"));
address.sendKeys("Mumbai");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[contains(normalize-space(),'Mumbai')]"
)
)
).click();</code></pre>
<h2>51. Google-Like Search Suggestions</h2>
<pre><code>WebElement search =
driver.findElement(By.name("q"));
search.sendKeys("Selenium");
List<WebElement> suggestions =
wait.until(
ExpectedConditions
.visibilityOfAllElementsLocatedBy(
By.cssSelector(".suggestion")
)
);
for (WebElement suggestion : suggestions) {
if (suggestion.getText()
.contains("Selenium WebDriver")) {
suggestion.click();
break;
}
}</code></pre>
<h2>52. Waiting for Multiple Suggestions</h2>
<pre><code>List<WebElement> suggestions =
wait.until(
ExpectedConditions
.visibilityOfAllElementsLocatedBy(
By.cssSelector(".suggestions li")
)
);</code></pre>
<h2>53. Presence vs Visibility</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Condition</th><th>Meaning</th><th>Use</th></tr>
<tr><td>Presence</td><td>Element exists in DOM</td><td>DOM-level checks</td></tr>
<tr><td>Visibility</td><td>Element exists and is visible</td><td>Visible suggestions</td></tr>
<tr><td>Clickable</td><td>Element is visible and enabled</td><td>Before clicking</td></tr>
<tr><td>Staleness</td><td>Element is no longer attached</td><td>After dynamic refresh</td></tr>
</table>
<h2>54. Presence of Suggestion</h2>
<pre><code>WebElement suggestion =
wait.until(
ExpectedConditions
.presenceOfElementLocated(
By.cssSelector(".suggestions li")
)
);</code></pre>
<h2>55. Visibility of Suggestion</h2>
<pre><code>WebElement suggestion =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.cssSelector(".suggestions li")
)
);</code></pre>
<h2>56. Clickability of Suggestion</h2>
<pre><code>WebElement suggestion =
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
);
suggestion.click();</code></pre>
<h2>57. Why Thread.sleep() Should Not Be the Main Strategy</h2>
<p>A fixed delay waits for a predetermined amount of time whether the suggestion is ready or not. Condition-based waits allow the test to proceed when the required state is reached.</p>
<pre><code>Thread.sleep(3000);</code></pre>
<p>For dynamic auto-suggest controls, an explicit wait is generally more precise.</p>
<h2>58. AJAX-Based Auto-Suggest</h2>
<p>Some auto-suggest components send a request to a server after text is entered.</p>
<pre><code>Enter search text
↓
AJAX/API request
↓
Server response
↓
JavaScript processes response
↓
Suggestion list updated
↓
Required option becomes available</code></pre>
<h2>59. Waiting for AJAX Suggestions</h2>
<pre><code>input.sendKeys("Ind");
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.cssSelector(".suggestions")
)
);
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
).click();</code></pre>
<h2>60. StaleElementReferenceException</h2>
<p>A stale element problem can occur when the application replaces the suggestion element after the test has already located it.</p>
<pre><code>WebElement option =
driver.findElement(
By.cssSelector(".suggestions li")
);
input.clear();
input.sendKeys("Ind");</code></pre>
<p>The old reference may no longer represent the current DOM element after the suggestion list refreshes.</p>
<h2>61. Re-Locating After Refresh</h2>
<pre><code>WebElement currentOption =
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
);
currentOption.click();</code></pre>
<h2>62. Waiting for Staleness</h2>
<pre><code>WebElement oldElement =
driver.findElement(
By.cssSelector(".suggestions li")
);
input.clear();
input.sendKeys("Ind");
wait.until(
ExpectedConditions.stalenessOf(
oldElement
)
);</code></pre>
<h2>63. NoSuchElementException</h2>
<p><code>NoSuchElementException</code> can occur when Selenium cannot locate the requested suggestion.</p>
<p>Possible reasons include:</p>
<ul>
<li>Incorrect locator</li>
<li>Suggestion has not loaded</li>
<li>Wrong suggestion text</li>
<li>Incorrect frame</li>
<li>DOM changed</li>
<li>Suggestion disappeared</li>
</ul>
<h2>64. TimeoutException</h2>
<p>A <code>TimeoutException</code> can occur when the expected condition is not satisfied within the specified timeout.</p>
<pre><code>WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);</code></pre>
<h2>65. ElementClickInterceptedException</h2>
<p>This can occur when another element or overlay prevents Selenium from clicking the suggestion.</p>
<p>Possible solutions include:</p>
<ul>
<li>Wait for the correct element state.</li>
<li>Wait for an overlay to disappear.</li>
<li>Scroll the element into view when appropriate.</li>
<li>Inspect overlapping elements.</li>
<li>Use JavaScript only as a controlled fallback.</li>
</ul>
<h2>66. Keyboard Navigation</h2>
<p>Some auto-suggest components support keyboard navigation.</p>
<pre><code>input.sendKeys("Ind");
input.sendKeys(Keys.ARROW_DOWN);
input.sendKeys(Keys.ENTER);</code></pre>
<h2>67. Selecting the Highlighted Suggestion</h2>
<pre><code>input.sendKeys("Mumbai");
input.sendKeys(Keys.ARROW_DOWN);
input.sendKeys(Keys.ENTER);</code></pre>
<p>This technique should be used only when the application's autocomplete widget supports keyboard navigation.</p>
<h2>68. Multiple Auto-Suggest Fields</h2>
<p>A form may contain several autocomplete fields, such as:</p>
<ul>
<li>Departure city</li>
<li>Destination city</li>
<li>Country</li>
<li>Product</li>
<li>Customer</li>
<li>Employee</li>
<li>Address</li>
</ul>
<h2>69. Departure and Destination Example</h2>
<pre><code>WebElement from =
driver.findElement(By.id("from"));
from.sendKeys("Delhi");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[normalize-space()='Delhi']"
)
)
).click();
WebElement to =
driver.findElement(By.id("to"));
to.sendKeys("Mumbai");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[normalize-space()='Mumbai']"
)
)
).click();</code></pre>
<h2>70. Dependent Auto-Suggest Fields</h2>
<p>Some fields depend on previous selections.</p>
<pre><code>Select Country
↓
City field becomes active
↓
Enter City
↓
City suggestions generated
↓
Select City</code></pre>
<h2>71. Dependent Dropdown Example</h2>
<pre><code>country.sendKeys("India");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
).click();
city.sendKeys("Mumbai");
wait.until(
ExpectedConditions.elementToBeClickable(
By.xpath(
"//li[normalize-space()='Mumbai']"
)
)
).click();</code></pre>
<h2>72. Auto-Suggest with Nested Elements</h2>
<p>Suggestions may contain multiple child elements.</p>
<pre><code><li class="suggestion">
<span class="city">Mumbai</span>
<span class="country">India</span>
</li></code></pre>
<h2>73. Locating Nested Suggestion</h2>
<pre><code>WebElement option =
driver.findElement(
By.xpath(
"//li[.//span[normalize-space()='Mumbai']]"
)
);
option.click();</code></pre>
<h2>74. Selecting by City and Country</h2>
<pre><code>WebElement option =
driver.findElement(
By.xpath(
"//li[.//span[normalize-space()='Mumbai']" +
" and .//span[normalize-space()='India']]"
)
);
option.click();</code></pre>
<h2>75. Getting Suggestion Text</h2>
<pre><code>String text =
option.getText();
System.out.println(text);</code></pre>
<h2>76. Verifying the Selected Value</h2>
<p>After selecting the suggestion, verify the value present in the input field.</p>
<pre><code>String actualValue =
input.getAttribute("value");
System.out.println(actualValue);</code></pre>
<h2>77. TestNG Assertion</h2>
<pre><code>import static org.testng.Assert.assertEquals;
String actual =
input.getAttribute("value");
assertEquals(
actual,
"India"
);</code></pre>
<h2>78. Using assertTrue()</h2>
<pre><code>import static org.testng.Assert.assertTrue;
assertTrue(
input.getAttribute("value")
.contains("India")
);</code></pre>
<h2>79. Verifying Suggestion Count</h2>
<pre><code>List<WebElement> suggestions =
driver.findElements(
By.cssSelector(".suggestions li")
);
assertTrue(
suggestions.size() > 0
);</code></pre>
<h2>80. Verifying a Specific Suggestion Exists</h2>
<pre><code>boolean found = false;
for (WebElement suggestion : suggestions) {
if (suggestion.getText()
.trim()
.equalsIgnoreCase("India")) {
found = true;
break;
}
}
assertTrue(found);</code></pre>
<h2>81. Verifying Suggestion Container</h2>
<pre><code>WebElement container =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.cssSelector(".suggestions")
)
);
assertTrue(
container.isDisplayed()
);</code></pre>
<h2>82. ARIA Attributes in Auto-Suggest</h2>
<p>Modern accessible autocomplete components may use ARIA attributes such as:</p>
<ul>
<li><code>role="combobox"</code></li>
<li><code>role="listbox"</code></li>
<li><code>role="option"</code></li>
<li><code>aria-expanded</code></li>
<li><code>aria-controls</code></li>
<li><code>aria-activedescendant</code></li>
</ul>
<h2>83. Locating an Option by ARIA Role</h2>
<pre><code>WebElement option =
driver.findElement(
By.cssSelector("[role='option']")
);</code></pre>
<h2>84. Locating a Specific ARIA Option</h2>
<pre><code>WebElement option =
driver.findElement(
By.xpath(
"//*[@role='option' and " +
"normalize-space()='India']"
)
);</code></pre>
<h2>85. Checking aria-expanded</h2>
<pre><code>String expanded =
input.getAttribute(
"aria-expanded"
);
System.out.println(expanded);</code></pre>
<h2>86. Verifying the Dropdown Is Open</h2>
<pre><code>String expanded =
input.getAttribute(
"aria-expanded"
);
assertEquals(
expanded,
"true"
);</code></pre>
<h2>87. Auto-Suggest Inside an iframe</h2>
<p>If the autocomplete component is inside an iframe, Selenium must switch to the iframe before interacting with its elements.</p>
<pre><code>driver.switchTo().frame(
driver.findElement(
By.id("searchFrame")
)
);
WebElement search =
driver.findElement(
By.id("city")
);
search.sendKeys("Mumbai");
driver.findElement(
By.xpath(
"//li[normalize-space()='Mumbai']"
)
).click();
driver.switchTo().defaultContent();</code></pre>
<h2>88. Why iframe Handling Is Required</h2>
<p>An iframe represents a separate browsing context. Selenium must switch into that context before locating elements inside it.</p>
<h2>89. Auto-Suggest Inside Shadow DOM</h2>
<p>Modern applications can use Shadow DOM to implement custom components. Selenium 4 provides APIs for accessing a shadow root.</p>
<pre><code>WebElement host =
driver.findElement(
By.cssSelector("search-component")
);
SearchContext shadowRoot =
host.getShadowRoot();
WebElement input =
shadowRoot.findElement(
By.cssSelector("input")
);
input.sendKeys("India");</code></pre>
<h2>90. Selecting Shadow DOM Suggestion</h2>
<pre><code>WebElement option =
shadowRoot.findElement(
By.cssSelector(".suggestion")
);
option.click();</code></pre>
<h2>91. Page Object Model for Auto-Suggest</h2>
<p>In a Page Object Model framework, auto-suggest functionality can be encapsulated inside page classes so that test cases remain clean and reusable.</p>
<pre><code>public class SearchPage {
private WebDriver driver;
private WebDriverWait wait;
private By searchBox =
By.id("search");
private By suggestions =
By.cssSelector(".suggestions li");
public SearchPage(WebDriver driver) {
this.driver = driver;
this.wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
}
public void searchAndSelect(
String searchText,
String expectedText) {
WebElement input =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
searchBox
)
);
input.clear();
input.sendKeys(searchText);
List<WebElement> options =
wait.until(
ExpectedConditions
.visibilityOfAllElementsLocatedBy(
suggestions
)
);
for (WebElement option : options) {
if (option.getText()
.trim()
.equalsIgnoreCase(
expectedText
)) {
option.click();
break;
}
}
}
}</code></pre>
<h2>92. Calling Page Object Method</h2>
<pre><code>SearchPage searchPage =
new SearchPage(driver);
searchPage.searchAndSelect(
"Ind",
"India"
);</code></pre>
<h2>93. Reusable Utility Method</h2>
<pre><code>public static void selectSuggestion(
WebDriver driver,
WebDriverWait wait,
By inputLocator,
String searchText,
By suggestionLocator) {
WebElement input =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
inputLocator
)
);
input.clear();
input.sendKeys(searchText);
WebElement suggestion =
wait.until(
ExpectedConditions
.elementToBeClickable(
suggestionLocator
)
);
suggestion.click();
}</code></pre>
<h2>94. Calling the Utility Method</h2>
<pre><code>selectSuggestion(
driver,
wait,
By.id("country"),
"Ind",
By.xpath(
"//li[normalize-space()='India']"
)
);</code></pre>
<h2>95. Generic Text-Based Utility</h2>
<pre><code>public static void selectSuggestionByText(
WebDriver driver,
WebDriverWait wait,
By inputLocator,
String searchText,
String expectedText) {
WebElement input =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
inputLocator
)
);
input.clear();
input.sendKeys(searchText);
By optionLocator =
By.xpath(
"//*[normalize-space()='" +
expectedText +
"']"
);
wait.until(
ExpectedConditions
.elementToBeClickable(
optionLocator
)
).click();
}</code></pre>
<h2>96. Common Locator Strategies</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Locator</th><th>Example</th><th>Use</th></tr>
<tr><td>ID</td><td><code>By.id("country")</code></td><td>Stable input field</td></tr>
<tr><td>CSS</td><td><code>By.cssSelector(".suggestions li")</code></td><td>Multiple suggestions</td></tr>
<tr><td>XPath text</td><td><code>By.xpath("//li[normalize-space()='India']")</code></td><td>Specific text</td></tr>
<tr><td>Data attribute</td><td><code>By.cssSelector("[data-value='India']")</code></td><td>Stable custom attribute</td></tr>
<tr><td>ARIA</td><td><code>By.cssSelector("[role='option']")</code></td><td>Accessible components</td></tr>
</table>
<h2>97. Locator Priority</h2>
<ol>
<li>Stable unique ID</li>
<li>Stable data attribute</li>
<li>Meaningful CSS selector</li>
<li>Stable relative XPath</li>
<li>ARIA attributes when appropriate</li>
<li>Visible text when stable</li>
</ol>
<h2>98. Common Mistake: Using Select</h2>
<p>Incorrect for a custom auto-suggest:</p>
<pre><code>WebElement element =
driver.findElement(
By.id("country")
);
Select select =
new Select(element);</code></pre>
<p>If the element is an <code>input</code>, <code>div</code>, or another non-<code>select</code> element, use normal WebElement interaction instead.</p>
<h2>99. Common Mistake: Clicking Immediately</h2>
<p>Incorrect:</p>
<pre><code>input.sendKeys("Ind");
driver.findElement(
By.xpath(
"//li[normalize-space()='India']"
)
).click();</code></pre>
<p>The suggestion may not have been rendered yet.</p>
<h2>100. Better Approach</h2>
<pre><code>input.sendKeys("Ind");
WebElement india =
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
);
india.click();</code></pre>
<h2>101. Common Mistake: Absolute XPath</h2>
<pre><code>/html/body/div[2]/div[1]/ul/li[3]</code></pre>
<p>Absolute XPath can be fragile because DOM changes can alter the complete path.</p>
<h2>102. Better Relative XPath</h2>
<pre><code>//ul[contains(@class,'suggestions')]//li[
normalize-space()='India'
]</code></pre>
<h2>103. Common Mistake: Generic li Locator</h2>
<p>Using only:</p>
<pre><code>By.tagName("li")</code></pre>
<p>may return unrelated list items elsewhere on the page.</p>
<h2>104. Better Scoped Locator</h2>
<pre><code>By.cssSelector(
".country-suggestions li"
)</code></pre>
<h2>105. Common Mistake: Overusing JavaScript</h2>
<p>JavaScript can be used as a fallback for special cases, but normal Selenium interactions should generally be preferred.</p>
<pre><code>JavascriptExecutor js =
(JavascriptExecutor) driver;
js.executeScript(
"arguments[0].click();",
option
);</code></pre>
<h2>106. When JavaScript May Be Used</h2>
<ul>
<li>A known UI layer prevents normal interaction.</li>
<li>A controlled fallback is required.</li>
<li>The application has an unusual interaction mechanism.</li>
<li>Debugging requires direct DOM interaction.</li>
</ul>
<h2>107. Handling Suggestions That Disappear</h2>
<p>Some autocomplete lists disappear when the input loses focus. Therefore, avoid unnecessary interactions between typing and selecting the result.</p>
<pre><code>input.sendKeys("India");
WebElement option =
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
);
option.click();</code></pre>
<h2>108. Handling Frequently Refreshed Suggestions</h2>
<pre><code>input.sendKeys("Ind");
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.cssSelector(".suggestions")
)
);
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
).click();</code></pre>
<h2>109. Negative Testing</h2>
<p>Negative testing checks how the application behaves when no matching suggestion exists.</p>
<pre><code>Enter invalid search
↓
Application searches
↓
No matching result
↓
"No results" message
↓
Verify expected behavior</code></pre>
<h2>110. No Results Example</h2>
<pre><code>input.sendKeys("XYZ123");
WebElement message =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.cssSelector(".no-results")
)
);
assertTrue(
message.getText()
.contains("No results")
);</code></pre>
<h2>111. Empty Input Test</h2>
<pre><code>input.clear();
List<WebElement> suggestions =
driver.findElements(
By.cssSelector(".suggestions li")
);
assertTrue(
suggestions.isEmpty()
);</code></pre>
<h2>112. Special Character Test</h2>
<pre><code>input.sendKeys("@#$%");</code></pre>
<p>Verify that the application handles special characters according to the expected requirements.</p>
<h2>113. Long Search Text</h2>
<pre><code>input.sendKeys(
"ThisIsAVeryLongSearchValueForTesting"
);</code></pre>
<h2>114. Rapid Typing Test</h2>
<p>Rapid typing can cause the suggestion list to change several times. The test should verify that the final suggestion corresponds to the final input value.</p>
<pre><code>input.sendKeys("I");
input.sendKeys("n");
input.sendKeys("d");</code></pre>
<h2>115. Clear and Search Again</h2>
<pre><code>input.clear();
input.sendKeys("India");
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='India']"
)
)
).click();</code></pre>
<h2>116. Disabled Suggestions</h2>
<p>Some applications may display suggestions that cannot be selected. The test should check whether the element is enabled or whether the application marks it as unavailable.</p>
<pre><code>if (option.isEnabled()) {
option.click();
}</code></pre>
<h2>117. Verifying Suggestion Is Displayed</h2>
<pre><code>assertTrue(
option.isDisplayed()
);</code></pre>
<h2>118. Verifying Suggestion Is Enabled</h2>
<pre><code>assertTrue(
option.isEnabled()
);</code></pre>
<h2>119. Complete Real-World Example</h2>
<pre><code>import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class CountryAutoSuggestTest {
public static void main(String[] args) {
WebDriver driver =
new ChromeDriver();
try {
driver.manage()
.window()
.maximize();
driver.get(
"https://example.com"
);
WebDriverWait wait =
new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
WebElement country =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
By.id("country")
)
);
country.clear();
country.sendKeys("Ind");
List<WebElement> suggestions =
wait.until(
ExpectedConditions
.visibilityOfAllElementsLocatedBy(
By.cssSelector(
".suggestions li"
)
)
);
boolean selected = false;
for (WebElement suggestion :
suggestions) {
String text =
suggestion
.getText()
.trim();
System.out.println(
"Suggestion: " + text
);
if (text.equalsIgnoreCase(
"India")) {
suggestion.click();
selected = true;
break;
}
}
if (!selected) {
throw new RuntimeException(
"Required suggestion not found"
);
}
String selectedValue =
country.getAttribute("value");
System.out.println(
"Selected: " +
selectedValue
);
} finally {
driver.quit();
}
}
}</code></pre>
<h2>120. Complete Automation Flow</h2>
<pre><code>Launch Browser
↓
Open Application
↓
Locate Auto-Suggest Input
↓
Enter Search Text
↓
Wait for Suggestion Container
↓
Retrieve Suggestions
↓
Compare Suggestion Text
↓
Find Required Suggestion
↓
Click Suggestion
↓
Read Input Value
↓
Verify Selected Value
↓
Close Browser</code></pre>
<h2>121. Mini Project: Flight Booking Auto-Suggest</h2>
<p>Create a Selenium automation project for a flight booking application containing departure and destination auto-suggest fields.</p>
<p><strong>Requirements:</strong></p>
<ol>
<li>Open the flight booking website.</li>
<li>Locate the departure field.</li>
<li>Enter the departure city.</li>
<li>Wait for suggestions.</li>
<li>Select the required departure location.</li>
<li>Locate the destination field.</li>
<li>Enter the destination city.</li>
<li>Wait for suggestions.</li>
<li>Select the required destination.</li>
<li>Verify both selected values.</li>
</ol>
<h2>122. Flight Booking Flow</h2>
<pre><code>Flight Booking Page
↓
Departure Field
↓
Enter "Delhi"
↓
Wait for Suggestions
↓
Select "Delhi"
↓
Destination Field
↓
Enter "Mumbai"
↓
Wait for Suggestions
↓
Select "Mumbai"
↓
Verify Both Fields</code></pre>
<h2>123. Reusable Flight Location Method</h2>
<pre><code>public void selectLocation(
By inputLocator,
String searchText,
String expectedLocation) {
WebElement input =
wait.until(
ExpectedConditions
.visibilityOfElementLocated(
inputLocator
)
);
input.clear();
input.sendKeys(searchText);
By optionLocator =
By.xpath(
"//li[normalize-space()='" +
expectedLocation +
"']"
);
wait.until(
ExpectedConditions
.elementToBeClickable(
optionLocator
)
).click();
}</code></pre>
<h2>124. E-Commerce Product Search Example</h2>
<pre><code>WebElement search =
driver.findElement(
By.id("productSearch")
);
search.clear();
search.sendKeys("Laptop");
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[contains(normalize-space(),'Laptop')]"
)
)
).click();</code></pre>
<h2>125. Employee Search Example</h2>
<pre><code>WebElement employee =
driver.findElement(
By.id("employee")
);
employee.sendKeys("Rahul");
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[normalize-space()='Rahul Sharma']"
)
)
).click();</code></pre>
<h2>126. Customer Search Example</h2>
<pre><code>WebElement customer =
driver.findElement(
By.id("customer")
);
customer.sendKeys("Amit");
wait.until(
ExpectedConditions
.elementToBeClickable(
By.xpath(
"//li[contains(normalize-space(),'Amit')]"
)
)
).click();</code></pre>
<h2>127. Address Search Example</h2>
<pre><code>WebElement address =
driver.findElement(
By.id("address")
);
address.sendKeys(
"Mumbai Maharashtra"
);
wait.until(
ExpectedConditions
.elementToBeClickable(
By.cssSelector(
".address-suggestion"
)
)
).click();</code></pre>
<h2>128. Interview Question: What Is an Auto-Suggest Dropdown?</h2>
<p>An Auto-Suggest Dropdown is a dynamic UI component that displays matching suggestions while the user types into an input field.</p>
<h2>129. Interview Question: Can We Use Select for Auto-Suggest?</h2>
<p>Normally no. The Selenium <code>Select</code> class is designed for HTML <code><select></code> elements. Custom autocomplete components using <code>input</code>, <code>div</code>, <code>ul</code>, or <code>li</code> should generally be handled using normal Selenium element interactions.</p>
<h2>130. Interview Question: Why Is Explicit Wait Required?</h2>
<p>Suggestions can be generated asynchronously after typing. Explicit waits allow the test to wait for a specific condition, such as the suggestion becoming visible or clickable.</p>
<h2>131. Interview Question: How Do You Select a Specific Suggestion?</h2>
<pre><code>List<WebElement> options =
driver.findElements(
By.cssSelector(
".suggestions li"
)
);
for (WebElement option : options) {
if (option.getText()
.trim()
.equalsIgnoreCase(
"India"
)) {
option.click();
break;
}
}</code></pre>
<h2>132. Interview Question: How Do You Handle Dynamic IDs?</h2>
<p>Use stable attributes, data attributes, meaningful classes, ARIA attributes, or relative XPath/CSS patterns instead of depending on changing portions of generated IDs.</p>
<h2>133. Interview Question: How Do You Handle Stale Elements?</h2>
<p>If JavaScript replaces the suggestion list, previously located elements may become stale. Re-locate the current element after the DOM update and use an appropriate wait.</p>
<h2>134. Interview Question: How Do You Verify the Selection?</h2>
<pre><code>String value =
input.getAttribute("value");
assertEquals(
value,
"India"
);</code></pre>
<h2>135. Interview Question: How Do You Handle Auto-Suggest Inside an iframe?</h2>
<pre><code>driver.switchTo().frame(
frameElement
);
// interact with auto-suggest
driver.switchTo().defaultContent();</code></pre>
<h2>136. Interview Question: How Do You Handle Auto-Suggest Inside Shadow DOM?</h2>
<pre><code>WebElement host =
driver.findElement(
By.cssSelector(
"search-component"
)
);
SearchContext shadowRoot =
host.getShadowRoot();
WebElement input =
shadowRoot.findElement(
By.cssSelector("input")
);</code></pre>
<h2>137. Interview Question: What If Suggestions Change While Typing?</h2>
<p>After the final search text is entered, wait for the current suggestion state and locate the required suggestion. If the DOM is replaced, use a fresh element lookup instead of an old WebElement reference.</p>
<h2>138. Interview Question: How Can Keyboard Navigation Be Automated?</h2>
<pre><code>input.sendKeys("Ind");
input.sendKeys(Keys.ARROW_DOWN);
input.sendKeys(Keys.ENTER);</code></pre>
<h2>139. Best Practices</h2>
<ul>
<li>Inspect the DOM before creating locators.</li>
<li>Determine whether the component is native or custom.</li>
<li>Do not use <code>Select</code> for custom auto-suggest controls.</li>
<li>Use stable locators.</li>
<li>Use explicit waits for dynamic suggestions.</li>
<li>Scope suggestion locators to the correct component.</li>
<li>Use <code>normalize-space()</code> where appropriate.</li>
<li>Re-locate elements after dynamic DOM updates.</li>
<li>Verify the final selected value.</li>
<li>Use Page Object Model in larger frameworks.</li>
<li>Use JavaScript only when a controlled fallback is actually required.</li>
<li>Test positive and negative scenarios.</li>
<li>Handle iframe and Shadow DOM scenarios correctly.</li>
</ul>
<h2>140. Common Problems and Solutions</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Problem</th><th>Possible Cause</th><th>Solution</th></tr>
<tr><td>Suggestion not found</td><td>Suggestion not loaded</td><td>Use explicit wait</td></tr>
<tr><td>Click fails</td><td>Overlay or wrong state</td><td>Wait for clickability</td></tr>
<tr><td>Stale element</td><td>DOM refreshed</td><td>Locate element again</td></tr>
<tr><td>Select exception</td><td>Element is not a select</td><td>Use WebElement interaction</td></tr>
<tr><td>Wrong suggestion selected</td><td>Generic locator</td><td>Use scoped locator</td></tr>
<tr><td>Dynamic ID</td><td>Generated identifier</td><td>Use stable attributes</td></tr>
<tr><td>Suggestions disappear</td><td>Input loses focus</td><td>Select immediately after waiting</td></tr>
<tr><td>Iframe element not found</td><td>Wrong browsing context</td><td>Switch to iframe</td></tr>
<tr><td>Shadow element not found</td><td>Shadow boundary</td><td>Access shadow root</td></tr>
</table>
<h2>141. Testing Scenarios</h2>
<ul>
<li>Enter valid search text.</li>
<li>Enter partial search text.</li>
<li>Enter invalid search text.</li>
<li>Verify suggestions appear.</li>
<li>Verify suggestion count.</li>
<li>Select a specific suggestion.</li>
<li>Select the first suggestion.</li>
<li>Verify the selected value.</li>
<li>Test keyboard navigation.</li>
<li>Test no-result behavior.</li>
<li>Test duplicate suggestions.</li>
<li>Test dynamic loading.</li>
<li>Test rapidly changing input.</li>
<li>Test clearing and re-entering text.</li>
<li>Test special characters.</li>
<li>Test long input.</li>
</ul>
<h2>142. Auto-Suggest Automation Formula</h2>
<pre><code>Locate Input
+
Enter Search Text
+
Wait for Suggestions
+
Locate Required Option
+
Click Option
+
Verify Selected Value
=
Reliable Auto-Suggest Automation</code></pre>
<h2>143. Quick Revision</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Topic</th><th>Key Point</th></tr>
<tr><td>Auto-Suggest</td><td>Dynamic list generated from user input</td></tr>
<tr><td>Input</td><td>Enter search text</td></tr>
<tr><td>Suggestion</td><td>Dynamic matching result</td></tr>
<tr><td>Select</td><td>Use only for actual HTML <code><select></code></td></tr>
<tr><td>Explicit Wait</td><td>Synchronize with dynamic UI</td></tr>
<tr><td>CSS Selector</td><td>Useful for suggestion collections</td></tr>
<tr><td>XPath</td><td>Useful for text-based selection</td></tr>
<tr><td>List<WebElement></td><td>Useful for multiple suggestions</td></tr>
<tr><td>Keys</td><td>Useful for keyboard navigation</td></tr>
<tr><td>iframe</td><td>Requires frame switching</td></tr>
<tr><td>Shadow DOM</td><td>Requires shadow-root access</td></tr>
<tr><td>Verification</td><td>Check final input value</td></tr>
</table>
<h2>144. Practical Checklist</h2>
<ul>
<li>Identify whether the dropdown is native or custom.</li>
<li>Inspect the input field.</li>
<li>Inspect the suggestion container.</li>
<li>Identify stable attributes.</li>
<li>Enter search text.</li>
<li>Wait for suggestions.</li>
<li>Locate the required option.</li>
<li>Click the option.</li>
<li>Verify the selected value.</li>
<li>Handle dynamic DOM changes.</li>
<li>Handle iframes if applicable.</li>
<li>Handle Shadow DOM if applicable.</li>
<li>Add negative test cases.</li>
<li>Create reusable methods.</li>
<li>Use Page Object Model for maintainable frameworks.</li>
</ul>
<h2>145. Selenium Training Resources</h2>
<p><strong>Selenium Training:</strong> <a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">https://www.justacademy.co/course-detail/selenium-training</a></p>
<p><strong>Register for Course Demo:</strong> <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">https://www.justacademy.co/register-for-course-demo</a></p>
<h2>146. Final Conclusion</h2>
<p>Auto-Suggest Dropdown automation is an important Selenium WebDriver concept because modern applications frequently use dynamically generated autocomplete components. Successful automation requires understanding the DOM, identifying stable locators, entering search text, waiting for dynamic suggestions, selecting the required option, and verifying the final value.</p>
<p>The most important rule is to distinguish a native HTML <code><select></code> from a custom autocomplete component. The Selenium <code>Select</code> class is specifically designed for <code><select></code> elements, while custom dropdowns normally require standard WebElement interactions. Proper explicit waits are also important because dynamic elements can appear or change after the initial page load.</p>
<p>By combining stable locators, explicit waits, dynamic element handling, keyboard interaction where appropriate, Page Object Model, reusable utility methods, and strong verification, Auto-Suggest Dropdowns can be automated reliably in Selenium WebDriver.</p>
</div>